<?php
/**
 * Created by PhpStorm.
 * User: Cristiano Ronaldo
 * Date: 12/27/13
 * Time: 12:16 PM
 */

class Users extends Eloquent{

    protected $table = 'users';

    public static function getUser(){
        $username = 'admin';
        $query = 'select * from users where username = ?';
        $result = DB::select($query, array($username));

        return $result;
    }

    public static function login($username, $password){

        $query = "select username, password from users where username = ? and password = ?";
        $result = DB::select($query, array($username, $password));

        return $result;
    }

    public static function register($username, $password, $email, $fname, $lname){

        date_default_timezone_set('Asia/Ho_Chi_Minh');

        $query = "insert into users (id, username, email, password, create_time, role_id, firstname, lastname)
         values (?,?,?,?,?,?,?,?)";
        $result = DB::insert($query, array('', $username, $email, $password, $date = date('Y-m-d H:i:s'), 1, $fname, $lname));

        return $result;
    }

}